package card;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: wwy
 * Date: 2024-11-24
 * Time: 22:53
 */
public class CardDemo {
    public static final String[] suits = {"♥", "♠", "♣", "♦"};
    List<Card> cardList = new ArrayList<>(52);

    public List<Card> buyCard() {
        for (int i = 1; i <= 13; i++) {
            for (int j = 0; j < 4; j++) {
                String suit = suits[j];
                int rank = i;
                Card card = new Card(suit, rank);
                cardList.add(card);
            }
        }
        return cardList;
    }
    private static void swap(List<Card> cardList,int i,int j){
        Card t=cardList.get(i);
        cardList.set(i,cardList.get(j));
        cardList.set(j,t);
    }
    public void shuffle(List<Card> cardList){
        Random random=new Random();
        for (int i = cardList.size()-1; i >0 ; i--) {
            int r= random.nextInt(i);
            swap(cardList,i,r);

        }
    }
    public List<List<Card>> play(List<Card> cardList){
        List<Card> card0=new ArrayList<>();
        List<Card> card1=new ArrayList<>();
        List<Card> card2=new ArrayList<>();
        List<List<Card>> card=new ArrayList<>();
        card.add(card0);
        card.add(card1);
        card.add(card2);
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 3; j++) {
                card.get(j).add(cardList.remove(0));
            }
        }
        System.out.println(card0);
        System.out.println(card1);
        System.out.println(card2);
        return card;
    }
}
